package com.licheedev.someext.recycler

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding

/**
 * @param enableHasStableIds true,启用 setHasStableIds(true)，让{@link #notifyDataSetChanged()}刷新数据时不闪烁
 */
abstract class SimpleBindingRecyclerAdapter<T, VB : ViewBinding>(enableHasStableIds: Boolean = true) :
    BindingRecyclerAdapter<T, VB>(enableHasStableIds) {

    override fun createViewHolderInstance(parent: ViewGroup, viewType: Int): BindingViewHolder<VB> {
        val vb = bindingInflate().invoke(LayoutInflater.from(parent.context), parent, false)
        return BindingViewHolder(vb)
    }

    /**
     * 返回 XxxBinding::inflate 函数引用
     */
    abstract fun bindingInflate(): (LayoutInflater, ViewGroup, Boolean) -> VB

}